package org.cfx.org.service.impl;

import org.cfx.org.domain.Department;
import org.cfx.org.mapper.DepartmentMapper;
import org.cfx.org.query.BaseQuery;
import org.cfx.org.query.DepartmentQuery;
import org.cfx.org.service.IDepartmentService;
import org.cfx.org.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public Department queryById(Long id) {
        return departmentMapper.queryById(id);
    }

    @Override
    public List<Department> queryAll() {
        return departmentMapper.queryAll();
    }

    @Override
    public PageInfo<Department> queryAllPage(DepartmentQuery departmentQuery) {

        Long count = departmentMapper.queryCount(departmentQuery);

        //判断count是否为空
        if (count == 0) {
            return new PageInfo<Department>();
        }else {
            List<Department> departments = departmentMapper.queryAllPage(departmentQuery);
            return new PageInfo<Department>(count,departments);
        }

    }

    @Override
    public List<Department> queryTree() {
        return departmentMapper.queryTree();
    }
}
